{% extends 'myadmin/index.html' %}

{% block title %}
<title>后台-商品列表</title>
{% endblock %}

{% block con %}

<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title  am-cf">商品列表</div>
                </div>

                <div class="widget-body  am-fr">
                    <div class="am-u-sm-12 am-u-md-6 am-u-lg-6">
                        <div class="am-form-group">
                            <div class="am-btn-toolbar">
                                <div class="am-btn-group am-btn-group-xs">
                                    <a href="{% url 'myadmin_goodsadd' %}" class="am-btn am-btn-default am-btn-success">
                                        <span class="am-icon-plus"></span> 新增
                                    </a>
                                </div>
                            </div>
                        </div>
                    </div>
                <!-- form表单不写提交地址默认提交到本页面　默认就是get提交方式 -->
                <form>
                    <div class="am-u-sm-12 am-u-md-6 am-u-lg-3">
                        <div class="am-form-group tpl-table-list-select">
                            <select name="types" data-am-selected="{btnSize: 'sm'}" style="display: none;">
                              <option value="title" {% if request.GET.types == 'title' %} selected {% endif %}>商品标题</option>
                              <option value="price" {% if request.GET.types == 'price' %} selected {% endif %}>价格</option>
                              <option value="store" {% if request.GET.types == 'store' %} selected {% endif %}>库存</option>
                              <option value="clicknum" {% if request.GET.types == 'clicknum' %} selected {% endif %}>点击量</option>
                              <option value="ordernum" {% if request.GET.types == 'ordernum' %} selected {% endif %}>购买量</option>
                              <option value="status" {% if request.GET.types == 'status' %} selected {% endif %}>状态</option>
                            </select>
                        </div>
                    </div>
                    <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
                        <div class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
                            <input name='keywords' type="text" class="am-form-field ">
                            <span class="am-input-group-btn">
                                <button id='search' class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search"></button>
                            </span>
                        </div>
                    </div>
                </form>



                    <div class="am-u-sm-12">
                        <table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black ">
                            <thead>
                                <tr>
                                    <th>id</th>
                                    <th>商品图</th>
                                    <th>商品标题</th>
                                    <th>所属分类</th>
                                    <th>价格</th>
                                    <th>库存</th>
                                    <th>点击量</th>
                                    <th>购买量</td>
                                    <th>状态</th>
                                    <th>发布时间</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for i in goodslist %}
                                <tr>
                                    <td>{{i.id}}</td>
                                    <td>
                                        <img src="{{ i.pic_url }}" class="tpl-table-line-img" alt="">
                                    </td>
                                    <td class="am-text-middle">{{ i.title }}</td>
                                    <td class="am-text-middle">{{ i.cateid.name }}</td>
                                    <td class="am-text-middle">{{ i.price }}</td> 
                                    <td class="am-text-middle">{{ i.store }}</td> 
                                    <td class="am-text-middle">{{ i.clicknum }}</td> 
                                    <td class="am-text-middle">{{ i.ordernum }}</td> 

                                    <td class="am-text-middle">
                                        {% if i.status == 0 %}
                                            新品
                                        {% elif i.status == 1 %}
                                            热卖
                                        {% else %}
                                            下架
                                        {% endif %}
                                    </td> 
                                    <td class="am-text-middle">{{ i.addtime }}</td> 
                                   <td class="am-text-middle">
                                    <div class="tpl-table-black-operation">
                                        <a href="{% url 'myadmin_goodsedit' i.id %}">
                                            <i class="am-icon-pencil"></i> 编辑
                                        </a>
                                        <a href="{% url 'myadmin_goodsdel' i.id %}" class="tpl-table-black-operation-del">
                                            <i class="am-icon-trash"></i> 删除
                                        </a>
                                    </div>
                                </td>


                                </tr>
                                {% endfor %}
                                <!-- more data -->
                            </tbody>
                        </table>
                    </div>
                    <div class="am-u-lg-12 am-cf">
                        <div class="am-fr">
                            <ul class="am-pagination tpl-pagination">
                                
                                {% load pagetag %}

                                <!-- requset 请求对象　num_pages显示的总页数 -->
                                {% Showpages goodslist.paginator.num_pages request %}

                                
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<script type="text/javascript">
     // 给搜索按钮绑定单击事件
    $('#search').click(function(){
        // 获取选框的值
        var v = $('select[name=types]').val()
        // 判断类型
        if(v == 'price'){
            // 获取输入的关键字,检测是否正确
            var k = $('input[name=keywords]').val()
            var reg = /^(\d+|\d+\.\d+),(\d+|\d+\.\d+)$/
            if(!reg.test(k)){
                alert('输入的格式不正确,格式为:100,200')
                return false;
            }
        }
        if(v == 'store'){
            // 获取输入的关键字,检测是否正确
            var k = $('input[name=keywords]').val()
            var reg = /^(\d+|\d+\.\d+),(\d+|\d+\.\d+)$/
            if(!reg.test(k)){
                alert('输入的格式不正确,格式为:100,200')
                return false;
            }
        }
         if(v == 'clicknum'){
            // 获取输入的关键字,检测是否正确
            var k = $('input[name=keywords]').val()
            var reg = /^(\d+|\d+\.\d+),(\d+|\d+\.\d+)$/
            if(!reg.test(k)){
                alert('输入的格式不正确,格式为:100,200')
                return false;
            }
        }
         if(v == 'ordernum'){
            // 获取输入的关键字,检测是否正确
            var k = $('input[name=keywords]').val()
            var reg = /^(\d+|\d+\.\d+),(\d+|\d+\.\d+)$/
            if(!reg.test(k)){
                alert('输入的格式不正确,格式为:100,200')
                return false;
            }
        }
    })
</script>

{% endblock %}